package com.xuecheng.content.controller;


import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;

import com.xuecheng.api.system.TeachplanApi;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划控制层
 * </p>
 */
@Slf4j
@RestController
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService teachplanService;


    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO vo) {
        //获取教育机构id
        Long companyId = SecurityUtil.getCompanyId();
        //将vo数据转为dto状态
        TeachplanDTO dto = TeachplanConvert.INSTANCE.vo2dto(vo);
        //调用service方法获得dto数据
        TeachplanDTO result = teachplanService.createOrModifyTeachplan(dto, companyId);

        return result;
    }

    @DeleteMapping("teachplan/{teachplanId}")
    public void removeTeachPlan(@PathVariable Long teachplanId) {

        // 1.获得公司Id
        Long companyId = SecurityUtil.getCompanyId();

        // 2.调用service方法
        teachplanService.removeTeachPlan(teachplanId, companyId);
    }


    @GetMapping("teachplan/{courseId}/tree-nodes")
    public TeachplanDTO queryTreeNodesByCourseId(@PathVariable Long courseId) {
        //获取公司id
        Long companyId = SecurityUtil.getCompanyId();

        //调用调用service方法
        TeachplanDTO teachplanDTO = teachplanService.queryTreeNodesByCourseId(courseId, companyId);
        return teachplanDTO;
    }
}